# -*- coding: utf-8 -*-

import os, time
import urllib.request

# 全局配置
save_path = 'H:\\新建文件夹\\车间工人1'  # 文件路径


# 下载图片
def save_imgs(img_urls):
    if not os.path.exists(save_path):  # 判断文件路径是否存在，若不在，则创建
        os.mkdir(save_path)
    for img, i in zip(img_urls, range(2200, len(img_urls) + 2200)):
        path_name = save_path + os.path.sep + str(i) + '.jpg'
        # time.sleep(1)
        try:
            urllib.request.urlretrieve(img, path_name)  # 打开图片地址，下载图片保存在本地，
        except:
            pass


if __name__ == '__main__':
    img_urls = []
    with open("img.txt", "r", encoding="utf-8") as f:
        while f.readline() != "":
            s = f.readline().strip("\n")
            img_urls.append(s)
    save_imgs(img_urls)
